<#import "/macro.ftl" as m>
<@m.page_header title='后台' />
<div id="page-content-wrapper">

<div id="page-title">

    <h3>
        <#if payGate>修改支付网关<#else>添加支付网关</#if>
    </h3>
 
</div>
<div class="pad10A">
<#if payGate> 
<form id="demo-form1" action="/paygate/paygateupdate/${payGate.id}" class="col-md-12" method="POST">
<#else>
<form id="demo-form1" action="/paygate/paygateadd" class="col-md-12" method="POST">
</#if>

	<#if payGate>
	<input type="hidden" name="id" value="${payGate.id}"/>
	</#if>
   <div class="form-row">
        <div class="form-label col-md-2">
            <label for="">
                网关名称:
                <span class="required">*</span>
            </label>
        </div>
        <div class="form-input col-md-8">
            <input type="text" id="gateName" name="gateName" data-trigger="change" data-required="true" class="parsley-validated" value="${payGate.gateName}">
        </div>
    </div>
    
    <div class="form-row">
        <div class="form-label col-md-2">
            <label for="">
                网关编码:
                <span class="required">*</span>
            </label>
        </div>
        <div class="form-input col-md-2">
            <select name="gateCode">
        		<option value="LLPay" <#if payGate.gateCode == 'LLPay'>selected</#if>>LLPay</option>
        		<option value="UMPay" <#if payGate.gateCode == 'UMPay'>selected</#if>>UMPay</option>
        		<option value="YeePay" <#if payGate.gateCode == 'YeePay'>selected</#if>>YeePay</option>
        		<option value="PayEco" <#if payGate.gateCode == 'PayEco'>selected</#if>>PayEco</option>
        		<option value="Baofoo" <#if payGate.gateCode == 'Baofoo'>selected</#if>>Baofoo</option>
        		<option value="JytPay" <#if payGate.gateCode == 'JytPay'>selected</#if>>JytPay</option>
        	</select>
        </div>
    </div>
    
    <div class="form-row">
	    <div class="form-label col-md-2">
	        <label for="">
	            优先级:
	            <span class="required">*</span>
	        </label>
	    </div>
	    <div class="form-input col-md-2">
	    	<input type="text" id="priority" name="priority" data-type="number" data-trigger="change" class="parsley-validated" value="${payGate.priority}">
	    </div>
	</div>
	
	<div class="form-row">
        <div class="form-label col-md-2">
            <label for="">
                使用标记:
                <span class="required">*</span>
            </label>
        </div>
        <div class="form-input col-md-8">
             <div class="form-checkbox-radio col-md-10">
                            <input type="radio" name="inuse" value="true" id="inuse"  <#if payGate.inuse == true >checked="" </#if>/>
                            <label for="">是</label>

                            <input type="radio" name="inuse" value="false" id="inuse" <#if payGate.inuse == false >checked="" </#if>/>
                            <label for="">否</label>
             </div>
        </div>
    </div>
    
    <div class="form-row">
        <div class="form-label col-md-2">
            <label for="">
                支持银行:
            </label>
        </div>
        <div class="form-input col-md-2">
            <a href="javascript:;" class="btn medium radius-all-4 mrg5A ui-state-default tooltip-button"
           	onclick="showAddBank();">
            <i class="glyph-icon icon-plus"></i>
        </a>
        </div>
    </div>
    
	<div class="form-row">
	    <div class="form-label col-md-2">
	    </div>
	    <div id="bank-rows" class="form-label col-md-10">
	        <div id="bank-row-template" class="hide" style="margin:8px 0;color:white">
	            <input type="hidden" name="bankIds">
	            <a id="updateid" href="javascript:;" class="btn large bg-gray radius-all-10" title="">
		            <span class="button-content">
		            </span>
		        </a>
	            <a id="deleteid" class="btn medium radius-all-4 mrg5A ui-state-default tooltip-button" title="" href="javascript:;"><i class="glyph-icon icon-minus"></i></a>
	        </div>
	    </div>
	</div>
    
    <div class="divider"></div>
    <div class="form-row">
        <input type="hidden" name="superhidden" id="superhidden">
       <div class="form-input col-md-10 col-md-offset-2">
                    <a href="javascript:;" class="btn medium primary-bg radius-all-4 col-md-2" id="demo-form-2-valid">
                        
                                                                         提交
                        
                 </a>
        </div>
    </div>   

</form>
</div>
</div>

<div class="hide" id="add-bank-template">
    <div class="pad10A">
        <form>
            <div class="form-row">
            	<div class="form-label col-md-3">
		            <label for="">
		                银行名称:
		                <span class="required">*</span>
		            </label>
		        </div>
                <div class="form-input col-md-9">
	                <select name="bankCode">
		        		<#list banklist as bank>
			        		<option value="${bank.bankCode}">${bank.bankName}</option>
			        	</#list>
		        	</select>
                </div>
            </div>
            <div class="form-row">
            	<div class="form-label col-md-4">
		            <label for="">
		                银行网关编码:
		                <span class="required">*</span>
		            </label>
		        </div>
                <div class="form-input col-md-6">
                    <input type="text" id="payBankCode" name="payBankCode" data-trigger="change" data-required="true" class="parsley-validated"/>
                </div>
            </div>
            <div class="form-row">
            	<div class="form-label col-md-3">
		            <label for="">
		                单笔限额:
		                <span class="required">*</span>
		            </label>
		        </div>
                <div class="form-input col-md-6">
                    <input type="text" id="singleLimit" name="singleLimit" data-type="number" data-trigger="change" data-required="true" class="parsley-validated">
                </div>
            </div>
            <div class="form-row">
            	<div class="form-label col-md-3">
		            <label for="">
		                单日限额:
		                <span class="required">*</span>
		            </label>
		        </div>
                <div class="form-input col-md-6">
                    <input type="text" id="dayLimit" name="dayLimit" data-type="number" data-trigger="change" data-required="true" class="parsley-validated">
                </div>
            </div>
            <div class="form-row">
            	<div class="form-label col-md-3">
		            <label for="">
		                单月限额:
		                <span class="required">*</span>
		            </label>
		        </div>
                <div class="form-input col-md-6">
                    <input type="text" id="monthLimit" name="monthLimit" data-type="number" data-trigger="change" data-required="true" class="parsley-validated">
                </div>
            </div>
            <div class="form-row">
           	    <div class="form-label col-md-3">
		            <label for="">
		                渠道:
		                <span class="required">*</span>
		            </label>
		        </div>
            	<div class="form-input col-md-9">
	                <div class="form-checkbox-radio col-md-12">
	                    <label><input name="webEnable" id="webEnable" type="checkbox" value="true" />Web </label>
	                    <label><input name="h5Enable" id="h5Enable" type="checkbox" value="true" />H5 </label>
	                    <label><input name="iOSEnable" id="iOSEnable" type="checkbox" value="true" />iOS </label>
	                    <label><input name="androidEnable" id="androidEnable" type="checkbox" value="true" />Android </label> 
	                </div>
                </div>
            </div>
            <div class="form-row">
            	<div class="form-label col-md-3">
		            <label for="">
		                使用标记:
		                <span class="required">*</span>
		            </label>
		        </div>
                <div class="form-input col-md-6">
                    <div class="form-checkbox-radio col-md-10">
                            <input type="radio" name="inuse" value="true" id="inuse"/>
                            <label for="">是</label>

                            <input type="radio" name="inuse" value="false" id="inuse" checked=""/>
                            <label for="">否</label>
             		</div>
                </div>
            </div>
        </form>
    </div>
</div>

<script type="text/javascript">

$(function(){
	$("#demo-form-2-valid").click(function(){
		$('#demo-form1').parsley('validate');
	    $('#demo-form1').trigger('submit');
	});
	
	var template = $('#bank-row-template');
<#list pblist as being>

    var row = template.clone();

    row.removeAttr('id');
    row.removeAttr('class');
    row.attr('id',${being.id});
    row.find('input').val(${being.id});
    row.find('#updateid span').html('${being.bankName}'+'  '+'编码'+'${being.payBankCode}'+'  '+'单笔'+'${being.singleLimit}'+'  '+'单日'+'${being.dayLimit}'+'  '+'单月'+'<#if being.monthLimit == 0 >无限制<#else>${being.monthLimit}</#if>');
    row.find('#deleteid').attr('onclick', 'deletebank("' + ${being.id} +'");');
    row.find('#updateid span').attr('onclick', 'updatebank("' + ${being.id} +'");');
    template.after(row);
</#list>
});

function showAddBank() {


    var template = $('#add-bank-template');
    var html = '<div id="dialog" title="添加银行"><div>' + template.html() + '</div></div>';

    $(html).dialog({
        minWidth: 400,
        minHeight: 300,
        model: !0,
        dialogClass: "modal-dialog",
        closeOnEscape: !0,
        close: function () {
            $(this).dialog('destroy');
        },
        buttons: {
            提交: function () {
                var valid = $('#dialog form').parsley('validate');
                if (!valid) {
                    return valid;
                }
                $.post("/paygatebank", $('#dialog form').serialize())
                        .done(function (data) {
                            if (data.status == 'success') {
                                $.jGrowl(data.message, {sticky: !1, position: 'top-right', theme: 'bg-green'});

                                var template = $('#bank-row-template');

                                var row = template.clone();
                                row.removeAttr('id');
                                row.removeAttr('class');

                                row.attr('id', data.data.id);
                                row.find('input').val(data.data.id);
                                row.find('#updateid span').html(data.data.bankName+'  '+'编码'+data.data.payBankCode+'  '+'单笔'+data.data.singleLimit+'  '+'单日'+data.data.dayLimit+'  '+'单月'+data.data.monthLimit);

                                row.find('#deleteid').attr('onclick', 'deletebank("' + data.data.id + '");');
                                row.find('#updateid span').attr('onclick', 'updatebank("' + data.data.id + '");');
                                template.after(row);
                            }
                        })
                        .fail(function () {
                            $.jGrowl('添加银行失败', {sticky: !1, position: 'top-right', theme: 'bg-red'});
                        });

                $('#dialog').dialog('close');
            }
        }
    });
}


function deletebank(id) {
    $.messager.confirm("提示", "确认删除该银行吗？", function () {

        $.post('/paygatebank/delete/' + id)
                .done(function (data) {
                    if (data.status == 'success') {
                        $.jGrowl(data.message, {sticky: !1, position: 'top-right', theme: 'bg-green'});

                        $('#bank-rows').find('div[id=' + data.data + ']').remove();
                    }
                })
                .fail(function () {
                    $.jGrowl('删除银行失败', {sticky: !1, position: 'top-right', theme: 'bg-red'});
                });
    });
}


function updatebank(id) {
    $.get('/paygatebank/showupdate/' + id)
            .done(function (data) {
                    var html = '<div id="dialog" class="hide" title="修改银行"><div class="pad10A">' + data + '</div></div>';
                    $(html).dialog({
                        minWidth: 400,
                        minHeight: 300,
                        model: !0,
                        dialogClass: "modal-dialog",
                        closeOnEscape: !0,
                        close: function () {
                            $(this).dialog('destroy');
                        },
                        buttons: {
                            提交: function () {
                                var valid = $('#dialog form').parsley('validate');
                                if (!valid) {
                                    return valid;
                                }
                                $.post('/paygatebank/update/' + id, $('#dialog form').serialize())
                                        .done(function (data) {
                                            if (data.status == 'success') {

                                                $.jGrowl(data.message, {sticky: !1, position: 'top-right', theme: 'bg-green'});
                                                $('#' + data.data.id).find('#updateid span').html(data.data.bankName+'  '+'编码'+data.data.payBankCode+'  '+'单笔'+data.data.singleLimit+'  '+'单日'+data.data.dayLimit+'  '+'单月'+data.data.monthLimit);

                                            }
                                        })
                                        .fail(function () {
                                            $.jGrowl('修改银行失败', {sticky: !1, position: 'top-right', theme: 'bg-red'});
                                        });

                                $('#dialog').dialog('close');
                            }
                        }
                    });
            })
            .fail(function () {
                $.jGrowl('修改银行失败', {sticky: !1, position: 'top-right', theme: 'bg-red'});
            });

}

</script>